<% add_decidim_page_title(translated_attribute(proposal.title)) %>
<div class="component__show">
  <div class="card">
    <%= render partial: "decidim/admin/shared/adjacent_navigation", locals: { adjacent_paths: filtered_adjacent_paths(proposal, :proposal_path) } %>
    <div class="component__show_header">
      <h2 class="component__show_header-title">
        <%= decidim_html_escape(present(proposal).title).html_safe %>
      </h2>
    </div>

    <div class="component__show_nav">
      <div class="component__show_nav-author">
        <div class="component__show_nav-circle">
          <%= icon "award-line" %>
        </div>
        <div>
          <% coauthor_presenters_for(proposal).each do |presented_author| %>
            <li class="component__show_nav-author-title">
              <%= link_to_if(
                    presented_author.profile_path.present?,
                    presented_author.name,
                    presented_author.profile_path,
                    target: :blank
                  ) %>
              <% if presented_author.can_be_contacted? && presented_author.nickname != present(current_user).nickname %>
                <%= link_to_current_or_new_conversation_with(presented_author) %>
              <% end %>
            </li>
          <% end %>
          <span class="component__show_nav-author-date">
            <%= l proposal.created_at, format: :decidim_short %>
          </span>
        </div>
      </div>
      <div class="ml-auto">
        <%= link_to resource_locator(proposal).url, class: "button button__sm button__transparent-secondary", target: :blank, data: { "external-link": false } do %>
          <%= icon "eye-line", class: "fill-current" %>
          <%= t ".link" %>
        <% end %>
      </div>
    </div>

    <div class="component__show_grid">
      <div class="component__show_grid-item">
        <div class="card-section">
          <div class="row column">
            <span class="component__show-title"><%= t ".body" %></span>
            <p class="component__show-text">
              <%= simple_format(present(proposal).body(strip_tags: true)) %>
            </p>
          </div>
        </div>

        <% presented_likes = likes_presenters_for(proposal) %>
        <% if presented_likes.any? %>
          <%= render partial: "decidim/proposals/admin/proposals/likes", locals: { presented_likes:, proposal: } %>
        <% end %>

        <% if proposal.documents.any? %>
          <%= render partial: "decidim/proposals/admin/proposals/documents", locals: { proposal: } %>
        <% end %>

        <% if proposal.photos.any? %>
          <%= render partial: "decidim/proposals/admin/proposals/photos", locals: { proposal: } %>
        <% end %>

        <% proposal_meetings = proposal.linked_resources(:meetings, "proposals_from_meeting") %>
        <% if proposal_meetings.any? %>
          <%= render partial: "decidim/proposals/admin/proposals/meetings", locals: { proposal_meetings: } %>
        <% end %>

        <% if allowed_to?(:create, :proposal_note, proposal: proposal) %>
          <div class="card-section">
            <%= render "decidim/proposals/admin/proposal_notes/proposal_notes" %>
          </div>
        <% end %>

        <% if allowed_to?(:create, :proposal_answer, proposal: proposal) && !proposal.emendation? %>
          <div class="card-section">
            <%= render "decidim/proposals/admin/proposal_answers/form" %>
          </div>
        <% end %>

      </div>
      <div class="component__show_grid-item">
        <% if proposal.taxonomies.present? %>
          <div class="card-section">
            <div class="row column">
              <span class="component__show-title"><%= t("models.proposal.fields.taxonomies", scope: "decidim.proposals") %></span>
              <% proposal.taxonomies.each do |taxonomy| %>
                <div class="flex items-center gap-x-2 mt-2">
                  <%= icon "price-tag-3-line", class: "fill-gray" %>
                  <p class="component__show-icon-text">
                    <%= translated_attribute taxonomy.name %>
                  </p>
                </div>
              <% end %>
            </div>
          </div>
        <% end %>

        <div class="card-section">
          <div class="row column" data-votes>
            <span class="component__show-title"><%= t ".votes_count" %></span>
            <div class="flex items-center gap-x-2 mt-2">
              <%= icon "service-line", class: "fill-gray" %>
              <p class="component__show-icon-text" data-count>
                <%= proposal.proposal_votes_count %>
              </p>
              <div class="flex items-center gap-x-2 border-l border-gray pl-2">
                <%= icon "bar-chart-2-line", class: "fill-gray" %>
                <p class="component__show-icon-text" data-ranking>
                  <%= i18n_votes_ranking_for(proposal) %>
                </p>
              </div>
            </div>
          </div>
        </div>

        <div class="card-section">
          <div class="row column" data-likes>
            <span class="component__show-title"><%= t ".likes_count" %></span>
            <div class="flex items-center gap-x-2 mt-2">
              <%= icon "like", class: "fill-gray" %>
              <p class="component__show-icon-text" data-count>
                <%= proposal.likes_count %>
              </p>
              <div class="flex items-center gap-x-2 border-l border-gray pl-2">
                <%= icon "bar-chart-2-line", class: "fill-gray" %>
                <p class="component__show-icon-text" data-ranking>
                  <%= i18n_likes_ranking_for(proposal) %>
                </p>
              </div>
            </div>
          </div>
        </div>

        <div class="card-section">
          <div class="row column" data-amendments>
            <span class="component__show-title"><%= t ".amendments_count" %></span>
            <div class="flex items-center gap-x-2 mt-2" data-count>
              <%= icon "Decidim::Amendment", class: "fill-gray" %>
              <p class="component__show-icon-text">
                <%= proposal.amendments.count %>
              </p>
            </div>
          </div>
        </div>

        <div class="card-section">
          <div class="row column" data-comments>
            <span class="component__show-title"><%= t ".comments_count" %></span>
            <div class="flex items-center gap-x-2 mt-2">
              <%= icon "chat-1-line", class: "fill-gray" %>
              <p class="component__show-icon-text" data-count>
                <%= proposal.comments_count %>
              </p>
              <div class="flex items-center gap-x-3 border-l border-gray pl-2" id="proposal-comments-alignment-count">
                <div>
                  <p class="component__show-icon-text" data-positive>
                    <%= icon "thumb-up-line", class: "fill-gray" %>
                    <%= proposal.comments.positive.count %>
                  </p>
                </div>
                <div>
                  <p class="component__show-icon-text" data-neutral>
                    <%= icon "scales-line", class: "fill-gray" %>
                    <%= proposal.comments.neutral.count %>
                  </p>
                </div>
                <div>
                  <p class="component__show-icon-text" data-negative>
                    <%= icon "thumb-up-fill", class: "fill-gray" %>
                    <%= proposal.comments.negative.count %>
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <% if proposal.evaluators.any? %>
    <div class="card">
      <div class="card-divider">
        <h2 class="card-title">
          <%= t ".evaluators" %>
        </h2>
      </div>

      <div class="card-section">
        <div class="row column">
          <strong><%= t ".assigned_evaluators" %>:</strong>
          <ul id="evaluators">
            <% proposal.evaluation_assignments.each do |assignment| %>
              <% presented_evaluator = present(assignment.evaluator) %>
              <li>
                <%= link_to(
                      presented_evaluator.name,
                      presented_evaluator.profile_path,
                      target: :blank
                    ) %>

                <% if allowed_to? :unassign_from_evaluator, :proposals, evaluator: assignment.evaluator %>
                  <%= icon_link_to(
                        "delete-bin-line",
                        evaluation_assignment_path(proposal_ids: [proposal.id], evaluator_role_ids: [assignment.evaluator_role.id]),
                        t(".remove_assignment"),
                        method: :delete,
                        data: { confirm: t(".remove_assignment_confirmation") },
                        class: "red-icon"
                      ) %>
                <% end %>
              </li>
            <% end %>
          </ul>
        </div>
      </div>
    </div>
  <% end %>
</div>
